<?php
error_reporting(E_ALL ^ E_NOTICE);

set_time_limit(0);
/*ini_set("memory_limit", "200M");
  mysql_connect("host=localhost dbname=miniglider  user=root  password=root")
   or die('Could not connect:'.mysql_last_error());
*/
$db_name="miniglider";  
 
$table_name="miniglider";  
 
$connection= @mysql_connect("localhost","root","root") or die(mysql_error());  
 
$db= @mysql_select_db($db_name,$connection) or die (mysql_error());  
 
$logdate =  mysql_query("SELECT DISTINCT date FROM `miniglider`");

while($everylogdate = mysql_fetch_array($logdate))
{
     //游戏总注册人数
    $loginPersonNum_query = mysql_query("SELECT count(DISTINCT deviceid) FROM miniglider where Jailbreak = '0'");

    $loginPersonNum = mysql_fetch_array($loginPersonNum_query);

     //日均活跃人数 
    $activePesonrNum_query = mysql_query("select(SELECT count(DISTINCT deviceid)  FROM miniglider where Jailbreak = '0')/(SELECT count( DISTINCT date )FROM miniglider)");
    $activePesonrNum = mysql_fetch_array($activePesonrNum_query);

    //日均活跃人次 activePesonrTime 一个人可能多次
    $activePesonrTime_query = mysql_query("select (SELECT count(deviceid)  FROM miniglider where Jailbreak = '0' )/(SELECT count( DISTINCT date )FROM miniglider)");
    $activePesonrTime = mysql_fetch_array($activePesonrTime_query);

    //日均人均打开次数  //DISTINCT deviceid
    $totalTodayGameTime_query = mysql_query("SELECT '$activePesonrTime[0]'/'$activePesonrNum[0]'");
    $totalTodayGameTime = mysql_fetch_array($totalTodayGameTime_query);
    //日均游戏时间 原始日志时间记录有问题，暂时将时间大于20000的用户过滤,修正后去掉条件
    $totalDayTotalTime_query = mysql_query("SELECT avg(dayTotalTime)  FROM miniglider where Jailbreak = '0' and dayTotalTime <20000"); 
    $totalDayTotalTime = mysql_fetch_array($totalDayTotalTime_query);

     //日均金钱获得
    $totalDayGetMoney_query = mysql_query("SELECT avg(dayGetMoney) FROM miniglider where Jailbreak = '0'");
    $totalDayGetMoney = mysql_fetch_array($totalDayGetMoney_query);

    //日均IAP金钱获得
    //$totalDayGetIAPMoney_query = mysql_query("SELECT avg(TotalGoldGet) FROM miniglider  where Jailbreak = '0'");
    //$totalDayGetIAPMoney = mysql_fetch_array($totalDayGetIAPMoney_query);

    //日均充值

    //$totalDayRecharge_query = mysql_query("SELECT avg(nGoldGainFromIAPToday) FROM miniglider where Jailbreak = '0'");
    //$totalDayRecharge = mysql_fetch_array($totalDayRecharge_query);
    
    //日均消费totalDayUsedMoney

    $totalDayUsedMoney_query = mysql_query("SELECT avg(dayUsedMoney)  FROM  miniglider where Jailbreak = '0'");
    $totalDayUsedMoney = mysql_fetch_array($totalDayUsedMoney_query);
     
    //日均注册人数
    $dayLoginPersonNum_query = mysql_query("select(SELECT count(DISTINCT deviceid) FROM miniglider where Jailbreak = '0')/(SELECT count( DISTINCT date )FROM miniglider where Jailbreak = '0')");

    $dayLoginPersonNum = mysql_fetch_array($dayLoginPersonNum_query);

    //totalDayNewusers 每日新注册 DISTINCT
    $totalDayNewusers_query = mysql_query("SELECT count(DISTINCT deviceid)  FROM  miniglider  where firstlogin = '$everylogdate[date]' and  Jailbreak = '0'");
    $totalDayNewusers = mysql_fetch_array($totalDayNewusers_query);

    //DayActivePesonrNum  每日活跃人数  //  日均TodayGameTime 活跃人数 今日的
    $dayActivePesonrNum_query = mysql_query("SELECT count(DISTINCT deviceid)  FROM miniglider  where date ='$everylogdate[date]' and  Jailbreak = '0' and date <> firstlogin");
    $dayActivePesonrNum = mysql_fetch_array($dayActivePesonrNum_query);

    //dayActivePesonrTime 每日活跃人次
    $dayActivePesonrTime_query = mysql_query("SELECT sum(dayPlayNowTime) FROM miniglider WHERE Jailbreak = '0' and date ='$everylogdate[date]' and date <> firstlogin");
    $dayActivePesonrTime = mysql_fetch_array($dayActivePesonrTime_query);
      //weekOneLandPesonrNum 过去7日内1次登录用户数
     $weekOneLandPesonrNum_query = mysql_query("  SELECT DISTINCT deviceid, date
        FROM miniglider
        WHERE Jailbreak = '0'  and date
        BETWEEN DATE_SUB( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND DATE_SUB( '$everylogdate[date]', INTERVAL 1
        DAY )
        GROUP BY deviceid
        HAVING count( 1 ) >0
        ");
     $weekOneLandPesonrNum = mysql_num_rows($weekOneLandPesonrNum_query);

     //weekActivePesonrNum   过去7日内2次登录用户数 每周活跃人数  SELECT * FROM miniglider   where DATE_SUB( date, INTERVAL 7 DAY ) <= date( '$everylogdate[date]' )
    $weekActivePesonrNum_query = mysql_query("  SELECT DISTINCT deviceid, date
        FROM miniglider
        WHERE Jailbreak = '0'  and date
        BETWEEN DATE_SUB( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND DATE_SUB( '$everylogdate[date]', INTERVAL 1
        DAY )
        GROUP BY deviceid
        HAVING count( 1 ) >1
        ");
    //$weekActivePesonrNum_query = mysql_query("SELECT count(DISTINCT deviceid)  FROM  miniglider  where date_add(date,interval 2 day)   and DATE_SUB( date, INTERVAL 7 DAY ) <= date( '$everylogdate[date]' )  and  Jailbreak = '0'");
    $weekActivePesonrNum = mysql_num_rows($weekActivePesonrNum_query);

    //weekLoyalPesonrNum  过去7日内3次登录用户数 每周忠诚用户人数
    $weekLoyalPesonrNum_query = mysql_query("SELECT DISTINCT deviceid, date
        FROM miniglider
        WHERE Jailbreak = '0'  and   date
        BETWEEN DATE_SUB( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND DATE_SUB( '$everylogdate[date]', INTERVAL 1
        DAY )
        GROUP BY deviceid
        HAVING count( 1 ) >2
        ");
   $weekLoyalPesonrNum = mysql_num_rows($weekLoyalPesonrNum_query);


    //weekCorePesonrNum   过去7日内4次用户数 每周核心用户人数
    $weekCorePesonrNum_query = mysql_query("SELECT DISTINCT deviceid, date
        FROM miniglider
        WHERE Jailbreak = '0'  and   date
        BETWEEN DATE_SUB( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND DATE_SUB( '$everylogdate[date]', INTERVAL 1
        DAY )
        GROUP BY deviceid
        HAVING count( 1 ) >3
        ");
    $weekCorePesonrNum = mysql_num_rows($weekCorePesonrNum_query);

    // 挂网等雇佣用户数 hirePesonrNum
    //$hirePesonrNum_query = mysql_query("SELECT count(DISTINCT deviceid)  FROM  miniglider  where  date ='$everylogdate[date]' and hireoutselftimes >0 and  Jailbreak = '0'");
   // $hirePesonrNum = mysql_fetch_array($hirePesonrNum_query);

    //  今日均人均游戏时间 原始日志时间记录有问题，暂时将时间大于20000的用户过滤,修正后去掉条件
    $dayTotalTime_query = mysql_query("select (SELECT sum(dayTotalTime)  FROM miniglider  where  date ='$everylogdate[date]' and  Jailbreak = '0'  and dayTotalTime <20000)/(SELECT count(DISTINCT deviceid)  FROM miniglider  where date ='$everylogdate[date]' and  Jailbreak = '0' and date <> firstlogin and dayTotalTime <20000)");
    $dayTotalTime = mysql_fetch_array($dayTotalTime_query);

    //  今日均消费金钱 DayUsedMoney 
    $dayUsedMoney_query = mysql_query("select (SELECT sum(dayUsedMoney)  FROM  miniglider   where date ='$everylogdate[date]' and  Jailbreak = '0')/('$dayActivePesonrNum[0]')");
    $dayUsedMoney = mysql_fetch_array($dayUsedMoney_query);

        //weekPayPesonrNum 周付费用户数 SELECT count( DISTINCT deviceid )  
    $weekPayPesonrNum_query = mysql_query("SELECT  DISTINCT deviceid FROM `miniglider` WHERE IAP1 >0 and  Jailbreak = '0' and date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' union 

        SELECT  DISTINCT deviceid FROM `miniglider` WHERE  IAP2 >0 and  Jailbreak = '0' and date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' union
        SELECT  DISTINCT deviceid FROM `miniglider` WHERE  IAP3 >0  and  Jailbreak = '0' and date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' union
        SELECT  DISTINCT deviceid FROM `miniglider` WHERE  IAP4 >0 and  Jailbreak = '0' and date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' union
        SELECT  DISTINCT deviceid FROM `miniglider` WHERE  IAP5 >0 and  Jailbreak = '0' and date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' union
        SELECT  DISTINCT deviceid FROM `miniglider` WHERE  IAP6 >0 and  Jailbreak = '0' and date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' ");
    $weekPayPesonrNum = mysql_num_rows($weekPayPesonrNum_query);
    //dayIAPGetMoney  今日人均 IAP 获得金钱
    $dayIAPGetMoney_query = mysql_query("select (SELECT sum(IAP1*99 + IAP2*199 + IAP3*199 + IAP4*299 + IAP5*499 + IAP6*1099)  FROM  miniglider  where  date ='$everylogdate[date]' and  Jailbreak = '0')/(SELECT count(deviceid)  FROM  miniglider  where  date ='$everylogdate[date]' and  Jailbreak = '0')");
    $dayIAPGetMoney = mysql_fetch_array($dayIAPGetMoney_query);
    //avgDayMoney  今日人均获得金钱
    $avgDayMoney_query = mysql_query("select (SELECT sum(dayGetMoney)  FROM  miniglider  where  date ='$everylogdate[date]' and  Jailbreak = '0')/(SELECT count(deviceid)  FROM  miniglider  where  date ='$everylogdate[date]' and  Jailbreak = '0')");
    $avgDayMoney = mysql_fetch_array($avgDayMoney_query);
    
    //dayNowMoney  今日人均现有金钱
    $dayNowMoney_query = mysql_query("select (SELECT sum(nowMoney)  FROM  miniglider  where  date ='$everylogdate[date]' and  Jailbreak = '0')/(SELECT count(deviceid)  FROM  miniglider  where  date ='$everylogdate[date]' and  Jailbreak = '0' )");
    $dayNowMoney = mysql_fetch_array($dayNowMoney_query);

    //最后退出 1界面 人数统计 Lastloginscreen10Num
    $Lastloginscreen10Num_query = mysql_query("SELECT count(distinct deviceid) FROM miniglider where Jailbreak = '0' and lastUi = 1  and date ='$everylogdate[date]'");
    $Lastloginscreen10Num = mysql_fetch_array($Lastloginscreen10Num_query);

        //最后退出 2界面 人数统计 Lastloginscreen10Num
    $Lastloginscreen21Num_query = mysql_query("SELECT count(distinct deviceid) FROM miniglider where Jailbreak = '0' and lastUi = 2  and date ='$everylogdate[date]'");
    $Lastloginscreen21Num = mysql_fetch_array($Lastloginscreen21Num_query);

        //最后退出 3界面 人数统计 Lastloginscreen10Num
    $Lastloginscreen22Num_query = mysql_query("SELECT count(distinct deviceid) FROM miniglider where Jailbreak = '0' and lastUi = 3  and date ='$everylogdate[date]'");
    $Lastloginscreen22Num = mysql_fetch_array($Lastloginscreen22Num_query);
        //最后退出 4界面 人数统计 Lastloginscreen10Num
    $Lastloginscreen23Num_query = mysql_query("SELECT count(distinct deviceid) FROM miniglider where Jailbreak = '0' and lastUi = 4  and date ='$everylogdate[date]'");
    $Lastloginscreen23Num = mysql_fetch_array($Lastloginscreen23Num_query);
        //最后退出 5界面 人数统计 Lastloginscreen10Num
    $Lastloginscreen24m_query = mysql_query("SELECT count(distinct deviceid) FROM miniglider where Jailbreak = '0' and lastUi = 5  and date ='$everylogdate[date]'");
    $Lastloginscreen24Num = mysql_fetch_array($Lastloginscreen24m_query);
        //最后退出 6界面 人数统计 Lastloginscreen10Num
    $Lastloginscreen31Num_query = mysql_query("SELECT count(distinct deviceid) FROM miniglider where Jailbreak = '0' and lastUi = 6  and date ='$everylogdate[date]'");
    $Lastloginscreen31Num = mysql_fetch_array($Lastloginscreen31Num_query);
        //最后退出 7界面 人数统计 Lastloginscreen10Num
    //$Lastloginscreen41Num_query = mysql_query("SELECT count(distinct deviceid) FROM miniglider where Jailbreak = '0' and lastUi = 7  and date ='$everylogdate[date]'");
    //$Lastloginscreen41Num = mysql_fetch_array($Lastloginscreen41Num_query);
        //最后退出 8界面 人数统计 Lastloginscreen10Num
    //$Lastloginscreen42Num_query = mysql_query("SELECT count(distinct deviceid) FROM miniglider where Jailbreak = '0' and lastUi = 8  and date ='$everylogdate[date]'");
    //$Lastloginscreen42Num = mysql_fetch_array($Lastloginscreen42Num_query);
        //最后退出 9界面 人数统计 Lastloginscreen10Num
    //$Lastloginscreen50Num_query = mysql_query("SELECT count(distinct deviceid) FROM miniglider where Jailbreak = '0' and lastUi = 9  and date ='$everylogdate[date]'");
    //$Lastloginscreen50Num = mysql_fetch_array($Lastloginscreen50Num_query);
        //最后退出 10界面 人数统计 Lastloginscreen10Num
    //$Lastloginscreen60Num_query = mysql_query("SELECT count(distinct deviceid) FROM miniglider where Jailbreak = '0' and lastUi = 10  and date ='$everylogdate[date]'");
    //$Lastloginscreen60Num = mysql_fetch_array($Lastloginscreen60Num_query);
        //最后退出 11界面 人数统计 Lastloginscreen10Num
    //$Lastloginscreen71Num_query = mysql_query("SELECT count(distinct deviceid) FROM miniglider where Jailbreak = '0' and lastUi = 11  and date ='$everylogdate[date]'");
    //$Lastloginscreen71Num = mysql_fetch_array($Lastloginscreen71Num_query);
        //最后退出 12界面 人数统计 Lastloginscreen10Num
    //$Lastloginscreen72Num_query = mysql_query("SELECT count(distinct deviceid) FROM miniglider where Jailbreak = '0' and lastUi = 12  and date ='$everylogdate[date]'");
    //$Lastloginscreen72Num = mysql_fetch_array($Lastloginscreen72Num_query);
        //最后退出 73界面 人数统计 Lastloginscreen10Num
  /*  $Lastloginscreen73Num_query = mysql_query("SELECT count(distinct deviceid) FROM miniglider where Jailbreak = '0' and lastUi = 73  and date ='$everylogdate[date]'");
    $Lastloginscreen73Num = mysql_fetch_array($Lastloginscreen73Num_query);
        //最后退出 80界面 人数统计 Lastloginscreen10Num
    $Lastloginscreen80Num_query = mysql_query("SELECT count(distinct deviceid) FROM miniglider where Jailbreak = '0' and lastUi = 80  and date ='$everylogdate[date]'");
    $Lastloginscreen80Num = mysql_fetch_array($Lastloginscreen80Num_query);
  */

 
   
        //newPayPesonrNum  新增付费人数
    /*SELECT count( DISTINCT deviceid )
        FROM miniglider a
        WHERE nGoldGainFromIAPToday >0
        AND date = '$everylogdate[date]'
        AND Jailbreak = '0'
        AND NOT
        EXISTS (

        SELECT DISTINCT deviceid
        FROM miniglider
        WHERE nGoldGainFromIAPToday >0
        AND date < '$everylogdate[date]'
        AND Jailbreak = '0'
        AND a.deviceid = deviceid
        )
        */
    $newPayPesonrNum_query = mysql_query("select A.deviceid  from (SELECT  DISTINCT deviceid FROM `miniglider` WHERE IAP1 >0  and 

        date 

        = DATE_SUB( 

        '$everylogdate[date]', INTERVAL 0
        DAY ) and  jailbreak = '0'  union 

        SELECT  DISTINCT deviceid FROM `miniglider` WHERE  IAP2 >0 and date = DATE_SUB( 

        '$everylogdate[date]', INTERVAL 0
        DAY ) and  jailbreak = '0' union
        SELECT  DISTINCT deviceid FROM `miniglider` WHERE  IAP3 >0 and date = DATE_SUB( 

        '$everylogdate[date]', INTERVAL 0
        DAY ) and  jailbreak = '0' union
        SELECT  DISTINCT deviceid FROM `miniglider` WHERE  IAP4 >0 and date = DATE_SUB( 

        '$everylogdate[date]', INTERVAL 0
        DAY ) and  jailbreak = '0' union
        SELECT  DISTINCT deviceid FROM `miniglider` WHERE  IAP5 >0 and date = DATE_SUB( 

        '$everylogdate[date]', INTERVAL 0
        DAY )  and  jailbreak = '0' union
        SELECT  DISTINCT deviceid FROM `miniglider` WHERE  IAP6 >0 and date = DATE_SUB( 

        '$everylogdate[date]', INTERVAL 0
        DAY ) and  jailbreak = '0')A left join (SELECT  DISTINCT deviceid FROM `miniglider` WHERE 

        IAP1 >0  and date
        BETWEEN DATE_SUB( '$everylogdate[date]', INTERVAL 360
        DAY )
        AND DATE_SUB( '$everylogdate[date]', INTERVAL 1
        DAY ) and  jailbreak = '0'  union 

        SELECT  DISTINCT deviceid FROM `miniglider` WHERE  IAP2 >0 and date
        BETWEEN DATE_SUB( '$everylogdate[date]', INTERVAL 360
        DAY )
        AND DATE_SUB( '$everylogdate[date]', INTERVAL 1
        DAY ) and  jailbreak = '0' union
        SELECT  DISTINCT deviceid FROM `miniglider` WHERE  IAP3 >0 and date
        BETWEEN DATE_SUB( '$everylogdate[date]', INTERVAL 360
        DAY )
        AND DATE_SUB( '$everylogdate[date]', INTERVAL 1
        DAY )  and  jailbreak = '0' union
        SELECT  DISTINCT deviceid FROM `miniglider` WHERE  IAP4 >0 and date
        BETWEEN DATE_SUB( '$everylogdate[date]', INTERVAL 360
        DAY )
        AND DATE_SUB( '$everylogdate[date]', INTERVAL 1
        DAY ) and  jailbreak = '0' union
        SELECT  DISTINCT deviceid FROM `miniglider` WHERE  IAP5 >0 and date
        BETWEEN DATE_SUB( '$everylogdate[date]', INTERVAL 360
        DAY )
        AND DATE_SUB( '$everylogdate[date]', INTERVAL 1
        DAY )  and  jailbreak = '0' union
        SELECT  DISTINCT deviceid FROM `miniglider` WHERE  IAP6 >0 and date
        BETWEEN DATE_SUB( '$everylogdate[date]', INTERVAL 360
        DAY )
        AND DATE_SUB( '$everylogdate[date]', INTERVAL 1
        DAY ) and  jailbreak = '0' )B on A.deviceid =B.deviceid  where B.deviceid  is null");
    $newPayPesonrNum = mysql_num_rows($newPayPesonrNum_query);
    //今日付费次数 paytimes
    $paytimes_query = mysql_query("SELECT sum(IAP1 + IAP2 + IAP3 + IAP4 + IAP5 + IAP6)  FROM  miniglider  where  date ='$everylogdate[date]' and  Jailbreak = '0'");
    $paytimes = mysql_fetch_array($paytimes_query);
    //今日付费用户数 PayPesonrNum
    $PayPesonrNum_query = mysql_query("SELECT  DISTINCT deviceid FROM `miniglider` WHERE IAP1 >0  and date = '$everylogdate[date]' and  Jailbreak = '0'  union 
        SELECT  DISTINCT deviceid FROM `miniglider` WHERE  IAP2 >0 and date = '$everylogdate[date]' and  Jailbreak = '0' union
        SELECT  DISTINCT deviceid FROM `miniglider` WHERE  IAP3 >0 and date = '$everylogdate[date]'  and  Jailbreak = '0' union
        SELECT  DISTINCT deviceid FROM `miniglider` WHERE  IAP4 >0 and date = '$everylogdate[date]' and  Jailbreak = '0' union
        SELECT  DISTINCT deviceid FROM `miniglider` WHERE  IAP5 >0 and date = '$everylogdate[date]'  and  Jailbreak = '0' union
        SELECT  DISTINCT deviceid FROM `miniglider` WHERE  IAP6 >0 and date = '$everylogdate[date]' and  Jailbreak = '0' ");
    $PayPesonrNum = mysql_num_rows($PayPesonrNum_query);

     $iap1_query = mysql_query(" SELECT sum(IAP1) FROM  miniglider  where  date ='$everylogdate[date]' and Jailbreak = '0' ");
    $iap1 = mysql_fetch_array($iap1_query);
   /* }
      var_dump($iap1_to[0]);*/
    //iap2
    $iap2_query = mysql_query("SELECT sum(IAP2) FROM  miniglider  where  date ='$everylogdate[date]' and Jailbreak = '0'");
    $iap2 = mysql_fetch_array($iap2_query);
    //iap3
    $iap3_query = mysql_query("SELECT sum(IAP3) FROM  miniglider  where  date ='$everylogdate[date]' and Jailbreak = '0'");
    $iap3 = mysql_fetch_array($iap3_query);
    //iap4
    $iap4_query = mysql_query("SELECT sum(IAP4) FROM  miniglider  where  date ='$everylogdate[date]' and Jailbreak = '0'");
    $iap4 = mysql_fetch_array($iap4_query);
    //iap5
    $iap5_query = mysql_query("SELECT sum(IAP5) FROM  miniglider  where  date ='$everylogdate[date]' and Jailbreak = '0'");
    $iap5 = mysql_fetch_array($iap5_query);
    // iap6
     $iap6_query = mysql_query("SELECT sum(IAP6) FROM  miniglider  where  date ='$everylogdate[date]' and Jailbreak = '0'");
     $iap6 = mysql_fetch_array($iap6_query);

     //WeekNewPayPesonrNum 过去7日内新增注册用户数
     $WeekNewPayPesonrNum_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM miniglider
        WHERE firstlogin
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND Jailbreak = '0'");
     $WeekNewPayPesonrNum = mysql_fetch_array($WeekNewPayPesonrNum_query);
     //MonthLandTwicePesonrNum 过去30日内2次登录用户数
        $MonthLandTwicePesonrNum_query = mysql_query("SELECT DISTINCT deviceid, date
        FROM miniglider
        WHERE Jailbreak = '0'
        AND date
        BETWEEN DATE_SUB( '$everylogdate[date]', INTERVAL 30
        DAY )
        AND DATE_SUB( '$everylogdate[date]', INTERVAL 1
        DAY )
        GROUP BY deviceid
        HAVING count( 1 ) >1 ");
     $MonthLandTwicePesonrNum = mysql_num_rows($MonthLandTwicePesonrNum_query);
     //WeekPayRechargeNum 周付费用户充值笔数
             $WeekPayRechargeNum_query = mysql_query("SELECT sum( IAP1 + IAP2 + IAP3 + IAP4 + IAP5 + IAP6)
        FROM miniglider
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND Jailbreak = '0'
        ");
     $WeekPayRechargeNum = mysql_fetch_array($WeekPayRechargeNum_query);

         //dayRechargeNum  今日人均充值笔数
   $dayRechargeNum_query = mysql_query("select '$paytimes[0]'/'$PayPesonrNum'");
   $dayRechargeNum = mysql_fetch_array($dayRechargeNum_query);
   //weekPayARPU 周付费用户ARPU值 =周付费总额/周付费人数
    $weekPayARPU_query = mysql_query("SELECT (
        SELECT sum( IAP1*99 + IAP2*199 + IAP3*199 + IAP4*299 + IAP5*499 + IAP6*1099)
        FROM miniglider
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND Jailbreak = '0'
        ) / (
        '$weekPayPesonrNum' )");
    $weekPayARPU = mysql_fetch_array($weekPayARPU_query); 
    
    //weekActiveARPU 周活跃用户ARPU值
    $weekActiveARPU_query = mysql_query("SELECT (
        SELECT sum(  IAP1*99 + IAP2*199 + IAP3*199 + IAP4*299 + IAP5*499 + IAP6*1099)
        FROM miniglider
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND Jailbreak = '0'
        ) / ($weekActivePesonrNum) ");
   $weekActiveARPU = mysql_fetch_array($weekActiveARPU_query);
   
       //weekLogARPU 周登陆用户ARPU值  = 周付费用户/周登陆人数(活跃用户+新用户)  
   $weekLogARPU_query = mysql_query("SELECT (
        SELECT sum(  IAP1*99 + IAP2*199 + IAP3*199 + IAP4*299 + IAP5*499 + IAP6*1099)
        FROM miniglider
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND Jailbreak = '0'
        ) / (
        SELECT count( DISTINCT deviceid )
        FROM miniglider
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND Jailbreak = '0' ) ");
      $weekLogARPU = mysql_fetch_array($weekLogARPU_query);
      //weekWastageRate  周活跃用户流失率 上周活跃用户在本周没有登陆过游戏的用户数，除以上周的活跃人数。
      $weekWastageRate_query = mysql_query("SELECT concat(round( (
        SELECT (
        SELECT count( a.deviceid )
        FROM weekActive a
        WHERE a.date = date_sub('$everylogdate[date]',interval 7 day)  
        AND a.deviceid NOT
        IN (
        SELECT DISTINCT deviceid
        FROM miniglider
        WHERE Jailbreak = '0'
        AND date
        BETWEEN DATE_SUB('$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) / (
        SELECT count( 1 )
        FROM weekActive
        WHERE date = date_sub('$everylogdate[date]',interval 7 day))
        ) *100,2), '%'
        )  ");
     $weekWastageRate = mysql_fetch_array($weekWastageRate_query); 
     //weekPayRate  周活跃用户付费率 周付费用户数除以周活跃人数
    //$weekPayRate_query = mysql_query("select '$weekPayPesonrNum[0]'/'$weekActivePesonrNum[0]'");
    $weekPayRate_query = mysql_query("SELECT concat(round( '$weekPayPesonrNum'/  '$weekActivePesonrNum' *100,2), '%' ) ");
    $weekPayRate = mysql_fetch_array($weekPayRate_query);
    //weekLogPayRate周登陆用户付费率 周付费用户数除以周登陆人数
    $weekLogPayRate_query = mysql_query("SELECT concat(round( '$weekPayPesonrNum'/  '$weekOneLandPesonrNum' *100,2), '%' ) ");
    $weekLogPayRate = mysql_fetch_array($weekLogPayRate_query);
       //weekPayWastageRate  周付费用户流失率 上周有付费行为而本周7天未登陆的用户数除以上周的付费用户数  
    $weekPayWastageRate_query = mysql_query("SELECT concat( round((
        SELECT (
        SELECT count( a.deviceid )
        FROM weekPay a
        WHERE a.date = date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND a.deviceid NOT
        IN (
        SELECT DISTINCT deviceid
        FROM miniglider
        WHERE Jailbreak = '0'
        AND date
        BETWEEN DATE_SUB( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) / (
        SELECT count( 1 )
        FROM weekPay
        WHERE date =  date_sub('$everylogdate[date]',interval 7 day) )
        ) *100 ,2), '%'
        ) ");
     $weekPayWastageRate = mysql_fetch_array($weekPayWastageRate_query);
     //周付费用户人均充值笔数
     $weekPayPesonrTime_query = mysql_query("SELECT '$WeekPayRechargeNum[0]'/'$weekPayPesonrNum'");
     $weekPayPesonrTime = mysql_fetch_array($weekPayPesonrTime_query);

   
 $sql="REPLACE INTO report_nojailbreak (logdate,loginPersonNum,activePesonrNum,activePesonrTime,totalDayTotalTime,
                                        totalDayGetMoney,totalDayRecharge,totalDayUsedMoney,dayLoginPersonNum,
                                        totalDayNewusers,dayActivePesonrNum,dayActivePesonrTime,weekActivePesonrNum,weekLoyalPesonrNum,weekCorePesonrNum,
                                        hirePesonrNum,dayTotalTime,dayUsedMoney,weekPayPesonrNum,dayIAPGetMoney,
                                        avgDayMoney,dayNowMoney,
                                        Lastloginscreen10Num,Lastloginscreen21Num,Lastloginscreen22Num,Lastloginscreen23Num,Lastloginscreen24Num,
                                        Lastloginscreen31Num,Lastloginscreen41Num,Lastloginscreen42Num,Lastloginscreen50Num,Lastloginscreen60Num,
                                        Lastloginscreen71Num,Lastloginscreen72Num,Lastloginscreen73Num,Lastloginscreen80Num,
                                        weekPayARPU,weekActiveARPU,weekLogARPU,weekWastageRate,weekPayRate,weekLogPayRate,weekPayWastageRate,
                                        weekPayPesonrTime,playerLevel,newPayPesonrNum,paytimes,PayPesonrNum,
                                        iap1,iap2,iap3,iap4,iap5,iap6,iap7,iap8,iap9,iap10,totalDayPlayTime,
                                        weekOneLandPesonrNum,WeekNewPayPesonrNum,MonthLandTwicePesonrNum,WeekPayRechargeNum,dayRechargeNum) 
                  VALUES('$everylogdate[date]','$loginPersonNum[0]','$activePesonrNum[0]','$activePesonrTime[0]','$totalDayTotalTime[0]',
                         '$totalDayGetMoney[0]','$totalDayRecharge[0]','$totalDayUsedMoney[0]','$dayLoginPersonNum[0]',
                         '$totalDayNewusers[0]','$dayActivePesonrNum[0]','$dayActivePesonrTime[0]','$weekActivePesonrNum','$weekLoyalPesonrNum','$weekCorePesonrNum',
                          '$hirePesonrNum[0]','$dayTotalTime[0]','$dayUsedMoney[0]','$weekPayPesonrNum','$dayIAPGetMoney[0]',
                          '$avgDayMoney[0]','$dayNowMoney[0]',
                          '$Lastloginscreen10Num[0]','$Lastloginscreen21Num[0]','$Lastloginscreen22Num[0]','$Lastloginscreen23Num[0]','$Lastloginscreen24Num[0]',
                          '$Lastloginscreen31Num[0]','$Lastloginscreen41Num[0]','$Lastloginscreen42Num[0]','$Lastloginscreen50Num[0]','$Lastloginscreen60Num[0]',
                          '$Lastloginscreen71Num[0]','$Lastloginscreen72Num[0]','$Lastloginscreen73Num[0]','$Lastloginscreen80Num[0]',
                          '$weekPayARPU[0]','$weekActiveARPU[0]','$weekLogARPU[0]','$weekWastageRate[0]','$weekPayRate[0]','$weekLogPayRate[0]','$weekPayWastageRate[0]',
                          '$weekPayPesonrTime[0]','$level[0]','$newPayPesonrNum','$paytimes[0]','$PayPesonrNum',
                          '$iap1[0]','$iap2[0]','$iap3[0]','$iap4[0]','$iap5[0]','$iap6[0]','$iap7[0]','$iap8[0]','$iap9[0]','$iap10[0]','$totalTodayGameTime[0]',
                          '$weekOneLandPesonrNum','$WeekNewPayPesonrNum[0]','$MonthLandTwicePesonrNum','$WeekPayRechargeNum[0]','$dayRechargeNum[0]')";
$query= @mysql_query($sql,$connection) or die(mysql_error());  

}
?>
